package cn.xq.jltx.threecamerdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    private int step = 10;
    private ThreeDView mMy3dView;
    private Button mReset;
    private EditText mCenterX;
    private EditText mCenterY;
    private Button mRotateXAdd;
    private Button mRotateXDec;
    private Button mRotateYAdd;
    private Button mRotateYDec;
    private Button mRotateZAdd;
    private Button mRotateZDec;
    private Button mTranslateXAdd;
    private Button mTranslateXDec;
    private Button mTranslateYAdd;
    private Button mTranslateYDec;
    private Button mTranslateZAdd;
    private Button mTranslateZDec;

    private void assignViews() {
        mMy3dView = (ThreeDView) findViewById(R.id.my3dView);
        mReset = (Button) findViewById(R.id.reset);
        mCenterX = (EditText) findViewById(R.id.centerX);
        mCenterY = (EditText) findViewById(R.id.centerY);
        mRotateXAdd = (Button) findViewById(R.id.rotateXAdd);
        mRotateXDec = (Button) findViewById(R.id.rotateXDec);
        mRotateYAdd = (Button) findViewById(R.id.rotateYAdd);
        mRotateYDec = (Button) findViewById(R.id.rotateYDec);
        mRotateZAdd = (Button) findViewById(R.id.rotateZAdd);
        mRotateZDec = (Button) findViewById(R.id.rotateZDec);
        mTranslateXAdd = (Button) findViewById(R.id.translateXAdd);
        mTranslateXDec = (Button) findViewById(R.id.translateXDec);
        mTranslateYAdd = (Button) findViewById(R.id.translateYAdd);
        mTranslateYDec = (Button) findViewById(R.id.translateYDec);
        mTranslateZAdd = (Button) findViewById(R.id.translateZAdd);
        mTranslateZDec = (Button) findViewById(R.id.translateZDec);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        assignViews();
        mReset.setOnClickListener(mOnClickListener);
        mRotateXAdd.setOnClickListener(mOnClickListener);
        mRotateXDec.setOnClickListener(mOnClickListener);
        mRotateYAdd.setOnClickListener(mOnClickListener);
        mRotateYDec.setOnClickListener(mOnClickListener);
        mRotateZAdd.setOnClickListener(mOnClickListener);
        mRotateZDec.setOnClickListener(mOnClickListener);
        mTranslateXAdd.setOnClickListener(mOnClickListener);
        mTranslateXDec.setOnClickListener(mOnClickListener);
        mTranslateYAdd.setOnClickListener(mOnClickListener);
        mTranslateYDec.setOnClickListener(mOnClickListener);
        mTranslateZAdd.setOnClickListener(mOnClickListener);
        mTranslateZDec.setOnClickListener(mOnClickListener);
    }

    private View.OnClickListener mOnClickListener = new View.OnClickListener(){
        @Override
        public void onClick(View view) {
            if(view.getId() == R.id.reset){
                mMy3dView.reset();
            }else if(view.getId() == R.id.rotateXAdd){
                mMy3dView.setRotateX(step);
            }else if(view.getId() == R.id.rotateXDec){
                mMy3dView.setRotateX(-step);
            }else if(view.getId() == R.id.rotateYAdd){
                mMy3dView.setRotateY(step);
            }else if(view.getId() == R.id.rotateYDec){
                mMy3dView.setRotateY(-step);
            }else if(view.getId() == R.id.rotateZAdd){
                mMy3dView.setRotateZ(step);
            }else if(view.getId() == R.id.rotateZDec){
                mMy3dView.setRotateZ(-step);
            }else if(view.getId() == R.id.translateXAdd){
                mMy3dView.setTranslateX(step);
            }else if(view.getId() == R.id.translateXDec){
                mMy3dView.setTranslateX(-step);
            }else if(view.getId() == R.id.translateYAdd){
                mMy3dView.setTranslateY(step);
            }else if(view.getId() == R.id.translateYDec){
                mMy3dView.setTranslateY(-step);
            }else if(view.getId() == R.id.translateZAdd){
                mMy3dView.setTranslateZ(step);
            }else if(view.getId() == R.id.translateZDec){
                mMy3dView.setTranslateZ(-step);
            }
        }
    };
}
